﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelperPrototype.OtherForms
{
    public partial class XemPhieuNhapKho : Form
    {
        private string _maPhieuNhapKho;

        public XemPhieuNhapKho(string maPhieu)
        {
            InitializeComponent();
            _maPhieuNhapKho = maPhieu;
        }

        private void XemPhieuNhapKho_Load(object sender, EventArgs e)
        {
            loadData();
        }

        private void loadData()
        {
            // fill info
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            _DB.PhieuNhapKho p = dc.PhieuNhapKhos.Single(x => x.MaPhieu == _maPhieuNhapKho);
            txtMaPhieu.Text = p.MaPhieu;
            txtNguoiTao.Text = p.NguoiTao.Ten;
            txtNgayTao.Text = p.NgayTao.ToString();
            txtNoiDung.Text = p.NoiDung;
            txtDonDH.Text = p.MaDonDatHang;

            // fill grid
            int count = 1;
            _DB.DonDatHang ddh = p.DonDatHang;
            foreach (_DB.HangHoaDonDatHang h in ddh.HangHoaDonDatHangs)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dgvHangHoa);
                r.Cells[0].Value = count++;
                r.Cells[1].Value = h.PhieuDeNghiMuaHang_HangHoa.HangHoa.TenHangHoa;
                r.Cells[2].Value = h.PhieuDeNghiMuaHang_HangHoa.HangHoa_NhaCungCap.NhaCungCap.TenNhaCungCap;
                r.Cells[3].Value = h.PhieuDeNghiMuaHang_HangHoa.SoLuongNhapKho;
                r.Cells[4].Value = h.PhieuDeNghiMuaHang_HangHoa.HangHoa.DonVi;

                dgvHangHoa.Rows.Add(r);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            XemDonDatHang f = new XemDonDatHang(txtDonDH.Text);
            f.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
